home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 31
/
Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso
/
Aminet
/
util
/
gnu
/
xpdf-0.8-src.lha
/
xpdf-0.8-src
/
ltk
/
LTKWindow.cc
< prev
next >
Wrap
C/C++ Source or Header
|
1998-11-28
|
13KB
|
479 lines
//========================================================================
//
// LTKWindow.cc
//
// Copyright 1996 Derek B. Noonburg
//
//========================================================================
#ifdef __GNUC__
#pragma implementation
#endif
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/cursorfont.h>
#ifdef HAVE_X11_XPM_H
#include <X11/xpm.h>
#endif
#include "LTKConfig.h"
#include "LTKApp.h"
#include "LTKMenu.h"
#include "LTKWindow.h"
#include "LTKWidget.h"
#include "LTKBox.h"
#include "LTKBorder.h"
#ifdef XlibSpecificationRelease
#if XlibSpecificationRelease < 5
typedef char *XPointer;
#endif
#else
typedef char *XPointer;
#endif
static Bool isExposeEvent(Display *display, XEvent *e, XPointer w);
LTKWindow::LTKWindow(LTKApp *app1, GBool dialog1, char *title1,
char **iconData1, char *defaultWidgetName,
LTKBox *box1) {
app = app1;
dialog = dialog1;
title = new GString(title1);
iconData = iconData1;
width = 0;
height = 0;
widgets = NULL;
box = box1;
box->setParent(this);
selection = NULL;
savedCursor = None;
busyCursorNest = 0;
menu = NULL;
keyCbk = NULL;
propCbk = NULL;
layoutCbk = NULL;
if (defaultWidgetName)
defaultWidget = findWidget(defaultWidgetName);
else
defaultWidget = NULL;
keyWidget = NULL;
selectionWidget = NULL;
pasteWidget = NULL;
overWin = NULL;
xwin = None;
eventMask = ExposureMask | StructureNotifyMask | VisibilityChangeMask |
ButtonPressMask | ButtonReleaseMask | KeyPressMask;
installCmap = gFalse;
fgGC = bgGC = brightGC = darkGC = xorGC = None;
fontStruct = NULL;
next = NULL;
app->addWindow(this);
}
LTKWindow::~LTKWindow() {
if (xwin) {
XFreeFont(display, fontStruct);
XFreeGC(display, fgGC);
XFreeGC(display, bgGC);
XFreeGC(display, brightGC);
XFreeGC(display, darkGC);
XFreeGC(display, xorGC);
if (installCmap)
XFreeColormap(display, colormap);
XUnmapWindow(display, xwin);
XDestroyWindow(display, xwin);
}
app->setGrabWin(NULL);
app->delWindow(this);
delete title;
delete box;
if (selection)
delete selection;
if (menu)
delete menu;
}
LTKWidget *LTKWindow::addWidget(LTKWidget *widget) {
widget->setNext(widgets);
widgets = widget;
return widget;
}
LTKWidget *LTKWindow::delWidget(LTKWidget *widget) {
LTKWidget *w1, *w2;
for (w1 = NULL, w2 = widgets;
w2 && w2 != widget;
w1 = w2, w2 = w2->getNext()) ;
if (w2 == widget) {
if (w1)
w1->setNext(w2->getNext());
else
widgets = w2->getNext();
w2->setNext(NULL);
return w2;
}
return NULL;
}
LTKWidget *LTKWindow::findWidget(char *name) {
LTKWidget *widget;
for (widget = widgets; widget; widget = widget->getNext()) {
if (widget->getName() && !strcmp(widget->getName(), name))
break;
}
return widget;
}
void LTKWindow::setPropChangeCbk(LTKWindowPropCbk cbk) {
propCbk = cbk;
if (propCbk)
eventMask |= PropertyChangeMask;
else
eventMask &= ~PropertyChangeMask;
if (xwin != None)
XSelectInput(display, xwin, eventMask);
}
GBool LTKWindow::checkFills(char **err) {
// outer box must either have both xfill > 0 and yfill > 0
// (i.e., the window is resizable), or xfill = yfill = 0
// (i.e., the window is not resizable)
if ((box->getXFill() > 0) != (box->getYFill() > 0)) {
*err = "outer box must have matched xfill and yfill";
return gFalse;
}
// check consistency of box hierarchy
if (!box->checkFills(err))
return gFalse;
// everything checked out ok
*err = "";
return gTrue;
}
void LTKWindow::layout(int x, int y, int width1, int height1) {
XColor bgXcol;
XColor xcol;
XGCValues gcValues;
int minWidth, minHeight;
int width2, height2;
char *title1;
XSizeHints *sizeHints;
XWMHints *wmHints;
XClassHint *classHints;
XTextProperty windowName, iconName;
Atom protocol;
GBool newWin;
// create window and GC's so widgets can use font info, etc.
if (xwin == None) {
newWin = gTrue;
display = app->getDisplay();
screenNum = app->getScreenNum();
fgColor = app->getColorResource("foreground", LTK_FOREGROUND,
BlackPixel(display, screenNum), NULL);
bgColor = app->getColorResource("background", LTK_BACKGROUND,
WhitePixel(display, screenNum), &bgXcol);
xwin = XCreateSimpleWindow(display, RootWindow(display, screenNum),
(x < 0) ? 0 : x, (y < 0) ? 0 : y, 1, 1, 0,
fgColor, bgColor);
app->registerXWindow(xwin, this, NULL);
XSelectInput(display, xwin, eventMask);
gcValues.foreground = fgColor;
gcValues.background = bgColor;
gcValues.line_width = 0;
gcValues.line_style = LineSolid;
gcValues.graphics_exposures = True;
fontStruct = app->getFontResource("font", LTK_WIN_FONT);
gcValues.font = fontStruct->fid;
fgGC = XCreateGC(display, xwin,
GCForeground | GCBackground | GCLineWidth | GCLineStyle |
GCGraphicsExposures | GCFont,
&gcValues);
gcValues.foreground = bgColor;
bgGC = XCreateGC(display, xwin,
GCForeground | GCBackground | GCLineWidth | GCLineStyle |
GCGraphicsExposures,
&gcValues);
gcValues.foreground = ltkGetBrightColor(display, screenNum,
&bgXcol, fgColor);
brightGC = XCreateGC(display, xwin,
GCForeground | GCBackground | GCLineWidth |
GCLineStyle | GCGraphicsExposures,
&gcValues);
gcValues.foreground = ltkGetDarkColor(display, screenNum,
&bgXcol, fgColor);
darkGC = XCreateGC(display, xwin,
GCForeground | GCBackground | GCLineWidth |
GCLineStyle | GCGraphicsExposures,
&gcValues);
gcValues.foreground = fgColor ^ bgColor;
gcValues.function = GXxor;
xorGC = XCreateGC(display, xwin,
GCForeground | GCBackground | GCLineWidth | GCLineStyle |
GCGraphicsExposures | GCFunction,
&gcValues);
colormap = DefaultColormap(display, screenNum);
if (installCmap) {
// ensure that BlackPixel and WhitePixel are reserved in the
// new colormap
xcol.red = xcol.green = xcol.blue = 0;
XAllocColor(display, colormap, &xcol);
xcol.red = xcol.green = xcol.blue = 65535;
XAllocColor(display, colormap, &xcol);
colormap = XCopyColormapAndFree(display, colormap);
XSetWindowColormap(display, xwin, colormap);
}
} else {
newWin = gFalse;
}
// do layout
box->layout1();
minWidth = box->getWidth();
minHeight = box->getHeight();
if (box->getXFill() > 0 && box->getYFill() > 0) {
width2 = (width1 < minWidth) ? minWidth : width1;
height2 = (height1 < minHeight) ? minHeight : height1;
box->layout2(0, 0, width2, height2);
} else {
box->layout2(0, 0, minWidth, minHeight);
}
width = box->getWidth();
height = box->getHeight();
// set the real window size
if (newWin)
XResizeWindow(display, xwin, width, height);
// finish the layout and create the widget subwindows
box->layout3();
// set window properties and protocols
if (newWin) {
sizeHints = XAllocSizeHints();
wmHints = XAllocWMHints();
classHints = XAllocClassHint();
if (sizeHints && wmHints && classHints) {
title1 = title->getCString();
XStringListToTextProperty(&title1, 1, &windowName);
XStringListToTextProperty(&title1, 1, &iconName);
sizeHints->flags = PMinSize;
sizeHints->flags |= (x >= 0 || y >= 0) ? USPosition : PPosition;
sizeHints->flags |= (width1 >= 0 || height1 >= 0) ? USSize : PSize;
sizeHints->min_width = minWidth;
sizeHints->min_height = minHeight;
if (!(box->getXFill() > 0 && box->getYFill() > 0)) {
sizeHints->flags |= PMaxSize;
sizeHints->max_width = minWidth;
sizeHints->max_height = minHeight;
}
wmHints->input = True;
wmHints->initial_state = NormalState;
wmHints->flags = InputHint | StateHint;
#ifdef HAVE_X11_XPM_H
if (iconData) {
if (XpmCreatePixmapFromData(display, xwin, iconData,
&wmHints->icon_pixmap, NULL, NULL) ==
XpmSuccess)
wmHints->flags |= IconPixmap